const userService = require('./user.service')

class UserController {
  // 创建用户
  async create(ctx, next) {
    try {
      const user = ctx.request.body
      const result = await userService.create(user)
      ctx.body = result
    } catch (error) {
      ctx.throw(500, error.sqlMessage || error || "创建用户失败")
    }
  }
  // 更新密码
  async updatePassword(ctx, next) {
    try {
      const { id } = ctx.user
      const { password } = ctx.request.body
      const result = await userService.updatePassword(id, password)
      ctx.body = result
    } catch (error) {
      ctx.throw(500, error.sqlMessage || error || "更新密码失败")
    }
  }
}

module.exports = new UserController()
